package com.sugon.controller.device;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.DevMainBaseEntity;
import com.sugon.entity.DevPlanGcRecordEntity;
import com.sugon.service.DevPlanGcRecordService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * ${comments}Controller
 *
 * @author sugon
 * @date 2020-03-11 10:30:43
 */
@Controller
@RequestMapping("devplangcrecord")
public class DevPlanGcRecordController {
    @Autowired
    private DevPlanGcRecordService devPlanGcRecordService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("devplangcrecord:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DevPlanGcRecordEntity> devPlanGcRecordList = devPlanGcRecordService.queryList(query);
        int total = devPlanGcRecordService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(devPlanGcRecordList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("devplangcrecord:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        DevPlanGcRecordEntity devPlanGcRecord = devPlanGcRecordService.queryObject(id);

        return R.ok().put("devPlanGcRecord", devPlanGcRecord);
    }

    /**
     * 保存
     */
    @AutoLog("${comments}--保存")
    @RequestMapping("/save")
    @RequiresPermissions("devplangcrecord:save")
    @ResponseBody
    public R save(@RequestBody DevPlanGcRecordEntity devPlanGcRecord) {
        devPlanGcRecordService.save(devPlanGcRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @AutoLog("${comments}--修改")
    @RequestMapping("/update")
    @RequiresPermissions("devplangcrecord:update")
    @ResponseBody
    public R update(@RequestBody DevPlanGcRecordEntity devPlanGcRecord) {
        devPlanGcRecordService.update(devPlanGcRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @AutoLog("${comments}--删除")
    @RequestMapping("/delete")
    @RequiresPermissions("devplangcrecord:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        devPlanGcRecordService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<DevPlanGcRecordEntity> list = devPlanGcRecordService.queryList(params);

        return R.ok().put("list", list);
    }
    /**
     * 修改
     */
    @AutoLog("${comments}--修改")
    @RequestMapping("/assgin")
    @RequiresPermissions("devplangcrecord:assgin")
    @ResponseBody
    public R assgin(@RequestBody  DevPlanGcRecordEntity devPlanGcRecord) {
        devPlanGcRecordService.assgin(devPlanGcRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @AutoLog("维护工单选项--批量结束")
    @RequestMapping("/batchEnd")
//    @RequiresPermissions("devplangcrecord:delete")
    @ResponseBody
    public R batchEnd(@RequestBody Map<String, String[]> params) {
        String[] ids =params.get("ids");
        devPlanGcRecordService.batchEnd(ids);
        return R.ok();
    }


    /**
     * 查看信息
     */
    @RequestMapping("/infoList")
//    @RequiresPermissions("devplangcrecord:infoList")
    @ResponseBody
    public R infoList(@RequestBody Map<String, String> params) {
        List<DevPlanGcRecordEntity> list=devPlanGcRecordService.infoList(params);
        return R.ok().put("list", list);
    }

    @RequestMapping("/list2")
//    @RequiresPermissions("devplangcrecord:list")
    @ResponseBody
    public R list2(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DevMainBaseEntity> devPlanGcRecordList = devPlanGcRecordService.queryList2(query);
        int total = devPlanGcRecordService.queryTotal2(query);

        PageUtils pageUtil = new PageUtils(devPlanGcRecordList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
}
